//
//  ViewController.m
//  18-SQLite
//
//  Created by 曹曹 on 16/8/8.
//  Copyright © 2016年 曹曹. All rights reserved.
//

#import "ViewController.h"
#import "SQLiteDataBaseManager.h"
#import "Student.h"

@interface ViewController ()
@property (nonatomic, strong) SQLiteDataBaseManager *dataBaseManager;
@end

@implementation ViewController

- (IBAction)openSQLite:(id)sender {
    [_dataBaseManager openSQLite];
}
- (IBAction)closeSQLite:(id)sender {
    [_dataBaseManager closeSQLite];
}
- (IBAction)createTable:(id)sender {
    [_dataBaseManager createTable];
}
- (IBAction)insertStu:(id)sender {
    Student *stu = [[Student alloc] init];
    stu.stu_id = 438;
    stu.stu_name = @"韩国和小日本";
    [_dataBaseManager insertStu:stu];
}
- (IBAction)deleteStu:(id)sender {
//    Student *stu = [[Student alloc] init];
//    stu.stu_id = 438;
//    stu.stu_name = @"韩国和小日本";
//    [_dataBaseManager deleteStu:stu];
    [_dataBaseManager deleteAll];
}
- (IBAction)updateName:(id)sender {
    [_dataBaseManager updateOldName:@"韩国和小日本" newName:@"恩"];
}
- (IBAction)selectAll:(id)sender {
    NSArray *array = [_dataBaseManager selectAll];
    NSLog(@"%ld", array.count);
    NSLog(@"%@", array);
}


- (void)viewDidLoad {
    [super viewDidLoad];
    _dataBaseManager = [SQLiteDataBaseManager sharedManager];
    // sqlite3
    // 注意: 使用SQLite需要引入libsqlite3.0
    // libsqlite3.0 和 libsqlite3的区别
    // libsqlite3.0 是 libsqlite3的替身文件, 防止用户误删
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
